﻿using Microsoft.Extensions.Configuration;
using System;
using System.Data.SqlClient;
using PlatformNetCore.Common;
using PlatformNetCore.Common.Configuration;

namespace PlatformNetCore.Repository.Dapper
{
    public partial class Dapper : IDisposable
    {
        private bool isDisposed = false;
        public Dapper()
        {

        }
        ~Dapper()
        {
            Dispose(true);
        }
        public void Dispose()
        {
            Dispose(true);
            GC.SuppressFinalize(this);
        }

        protected virtual void Dispose(bool _isDisposed)
        {
            if (!isDisposed)
            {
                if (_isDisposed)
                {
                    //不能在此处dispose
                }
                isDisposed = true;
            }
        }
        public static SqlConnection GetSqlConnection()
        {
            SqlConnection connection = new SqlConnection(AppSettings.ConnString);
            try
            {
                connection.Open();
            }
            catch
            {
                connection.Close();
                connection.Open();
            }
            return connection;
        }
    }
}
